﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SelfManagement.Common;
using Ninject;
using SelfManagement.Web.Infrastructure;
using SelfManagement.Web.Models;
using SelfManagement.Web.Models.ViewModels;
using SelfManagement.Utility.Extensions;
using SelfManagement.IServices;
using SelfManagement.Database.POCO;
using SelfManagement.Services;

namespace SelfManagement.Web.Controllers
{
    public class SchoolController : CommonBaseController
    {
        [Inject]
        public ISchoolService SchoolService { get; set; }
        // GET: School
        public ActionResult Index()
        {
            ViewBag.Schools = SchoolService.Query(t => true).ToList();
            return View();
        }
        public string Delete()
        {
            School school = SchoolService.Get(s => s.SchoolName == "福州大学");
            SchoolService.Delete(school);
            return "delete ok";
        }
        public string Modify()
        {
            School school = SchoolService.Get(s => s.SchoolName == "师范大学");
            school.SchoolName = "吃饭大学";
            return "modify ok";
        }
        public string Init()
        {
            SchoolService.Insert(new School(){
                SchoolName="福州大学",
                ImagePath = "http://f.hiphotos.baidu.com/baike/c0%3Dbaike72%2C5%2C5%2C72%2C24/sign=14fe4bae277f9e2f6438155a7e598241/b90e7bec54e736d19a5b75409b504fc2d562692a.jpg"
            });
            List<School> Schools = new List<School>();
            Schools.Add(new School()
            {
                SchoolName = "闽江大学",
                ImagePath = "http://f.hiphotos.baidu.com/baike/c0%3Dbaike72%2C5%2C5%2C72%2C24/sign=14fe4bae277f9e2f6438155a7e598241/b90e7bec54e736d19a5b75409b504fc2d562692a.jpg"
            });
            Schools.Add(new School()
            {
                SchoolName = "理工大学",
                ImagePath = "http://f.hiphotos.baidu.com/baike/c0%3Dbaike72%2C5%2C5%2C72%2C24/sign=14fe4bae277f9e2f6438155a7e598241/b90e7bec54e736d19a5b75409b504fc2d562692a.jpg"
            });
            SchoolService.InsertBatch(Schools);
            return "init OK";
        }
    }
}